package com.base.vistter.iframe.bean;

import com.base.vistter.iframe.constant.StatusConstant;
import com.base.vistter.iframe.menu.ErrorLoginEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Integer code = StatusConstant.STATUS_OK;

    private String message = "操作成功";

    private T data;

    private Long timestamp = System.currentTimeMillis();

    public Result() {

    }
    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static<T> Result<T> error(String message) {
        return Result.error(StatusConstant.STATUS_ERR , message);
    }
    public static<T> Result<T> error(Integer errorCode , String message) {
        Result<T> result = new Result<T>();
        result.setCode(errorCode);
        result.setMessage(message);
        return result;
    }
    public static<T> Result<T> error(ErrorLoginEnum errorLoginEnum) {
        Result<T> result = new Result<T>();
        result.setCode(errorLoginEnum.getErrorCode());
        result.setMessage(errorLoginEnum.getErrorMessage());
        return result;
    }
    public static<T> Result<T> ok(T data) {
        Result<T> result = new Result<T>();
        result.setData(data);
        return result;
    }

    public static<T> Result<T> ok() {
        return new Result<T>();
    }


}
